package com.laowang.project.system.service.impl;

import java.util.List;

import com.laowang.common.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.laowang.project.system.mapper.MyCyhVipProMapper;
import com.laowang.project.system.domain.MyCyhVipPro;
import com.laowang.project.system.service.MyCyhVipProService;

/**
 * 会员推荐推广大使Service业务层处理
 *
 * @author laowang
 * @date 2024-01-18
 */
@Service
public class MyCyhVipProServiceImpl implements MyCyhVipProService {
    @Autowired
    private MyCyhVipProMapper myCyhVipProMapper;

    /**
     * 查询会员推荐推广大使
     *
     * @param id 会员推荐推广大使ID
     * @return 会员推荐推广大使
     */
    @Override
    public MyCyhVipPro selectMyCyhVipProById(Integer id) {
        return myCyhVipProMapper.selectMyCyhVipProById(id);
    }

    /**
     * 查询会员推荐推广大使列表
     *
     * @param myCyhVipPro 会员推荐推广大使
     * @return 会员推荐推广大使
     */
    @Override
    public List<MyCyhVipPro> selectMyCyhVipProList(MyCyhVipPro myCyhVipPro) {
        return myCyhVipProMapper.selectMyCyhVipProList(myCyhVipPro);
    }

    /**
     * 新增会员推荐推广大使
     *
     * @param myCyhVipPro 会员推荐推广大使
     * @return 结果
     */
    @Override
    public int insertMyCyhVipPro(MyCyhVipPro myCyhVipPro) {
        Integer vipLevel = myCyhVipPro.getVipLevel();
        if (vipLevel == null){
            throw new CustomException("会员不能为空");
        }
        Integer proId = myCyhVipPro.getProId();
        if (proId == null){
            throw new CustomException("推广大使不能为空");
        }
        MyCyhVipPro myCyhVipPro1 =  myCyhVipProMapper.selectMyCyhByVipPro(vipLevel,proId);
        if (myCyhVipPro1 != null){
            throw new CustomException("会员与推广大使信息已存在");
        }
        return myCyhVipProMapper.insertMyCyhVipPro(myCyhVipPro);
    }

    /**
     * 修改会员推荐推广大使
     *
     * @param myCyhVipPro 会员推荐推广大使
     * @return 结果
     */
    @Override
    public int updateMyCyhVipPro(MyCyhVipPro myCyhVipPro) {
        Integer vipLevel = myCyhVipPro.getVipLevel();
        if (vipLevel == null){
            throw new CustomException("会员不能为空");
        }
        Integer proId = myCyhVipPro.getProId();
        if (proId == null){
            throw new CustomException("推广大使不能为空");
        }
        MyCyhVipPro myCyhVipPro1 =  myCyhVipProMapper.selectMyCyhByVipPro(vipLevel,proId);
        if (myCyhVipPro1 != null){
            if (!myCyhVipPro1.getId().equals(myCyhVipPro.getId())){
                throw new CustomException("会员与推广大使信息已存在");
            }

        }
        return myCyhVipProMapper.updateMyCyhVipPro(myCyhVipPro);
    }

    /**
     * 批量删除会员推荐推广大使
     *
     * @param ids 需要删除的会员推荐推广大使ID
     * @return 结果
     */
    @Override
    public int deleteMyCyhVipProByIds(Integer[] ids) {
        return myCyhVipProMapper.deleteMyCyhVipProByIds(ids);
    }

    /**
     * 删除会员推荐推广大使信息
     *
     * @param id 会员推荐推广大使ID
     * @return 结果
     */
    @Override
    public int deleteMyCyhVipProById(Integer id) {
        return myCyhVipProMapper.deleteMyCyhVipProById(id);
    }
}
